home *** CD-ROM | disk | FTP | other *** search
- Dynamic Linked Lists with variable length items
-
- by Tony Rolfe
-
- edgewater@shoalhaven.net.au
-
- August 2000
-
- Original code by Dave Newton
-
-
- 1. Introduction
-
- DLL.bb2 V3.0 By Tony Rolfe (edgewater@shoalhaven.net.au)
-
- Dynamic Linked Lists variable sized items for BLITZ BASIC 2
-
- These are a functional replacement for the List Arrays supplied with Blitz
- Basic 2.
-
-
- The fundamental difference between these routines and standard list arrays
- is that there is no need to define the maximum size of a list. Standard
- Blitz Lists are defined with a command of the form
-
- DIM List Name.Type(MaxSize)
-
- With DLL the only limit on the number of entries is the amount of available
- memory. Actually, the number of entries is held in a longword variable so
- the real limit is about 2,000,000,000. If anyone has problems with this
- limit please let me know.
-
- All the original commands are replicated here. Command names have had an
- underscore added in the middle and the names fully capitalized. Thus, the
- original AddItem() command has been replaced by ADD_ITEM{}.
-
- A number of additional functions have also been added.
-
-
- In this archive you should find:
- This Readme file (DLL.Readme)
- An AmigaGuide version of this information (dll.Guide)
- DLL main routines (dll.bb2 and dll.asc)
- DLL quicksort routines (dllsort.bb2 and dllsort.asc)
- DLL example program (dllexample.bb2 and dllexample.asc)
- Sample Fatal_Error routine (Fatal_Error.bb2 and Fatal_Error.asc)
- 3 Options for String Compare Routines (Compare_Strings_X.bb2 and .asc)
-
- All the source code is provided as tokenised (.bb2) files and plain ASCII
- (.asc) files. This is so that if you have any tokenisation problems when
- loading the .bb2 files you can simply load the .asc files and then save
- them over the .bb2 files.
-
-
- 2. Distribution
-
- DLL is PD. It is "Do-What-You-Like-Ware".
-
- Feel free to copy it and distribute it as you see fit.
-
- If, however, you make any significant changes, please forward a copy
- of the changes to me so I can maintain a central copy of DLL.
-
- Neither Dave Newton nor I can accept any responsibility for any harm to
- hardware or software caused directly or indirectly from the use of this
- source code and/or extracts of this source code compiled.
-
- But a credit for these routines in your software/manual would be nice :).
-
-
- 3. Getting Started
-
- Before you start to use DLL you need to make one fundamental decision:
-
- How do you want a DLL function to behave if it encounters an unrecoverable
- error? The original (Dave Newton) version of DLL had the function return
- a True or False value to tell if it was successful. My own preference is
- for low level routines to handle their own errors and not bother returning
- to the calling routine if they couldn't perform their function.
-
- Immediately following the introductory comments in DLL.bb2, is the line
-
- #DLL_TRAP_ERRORS = 1 ;
-
- If you wish to maintain the original version of the code, set this flag to 0.
- This will make you use code like:
-
- If ADD_ITEM{*TheList}
- ; success
- Else
- ; handle the error
- Endif
-
- If you wish to have each routine handle its own errors, set the flag to 1.
- You will need to provide a function called Fatal_Error{}, which accepts a
- string argument. A sample is provided which simply displays the string
- and ends the program. The above code can now be replaced with:
-
- ADD_ITEM{*TheList}
-
- Having set the flag, save the file as a tokenized source. Now you can
- begin to use DLL.
-
-
-
- For each program, you also need to decide how the sort routines should
- handle string comparisons. Three string compare routines are provided.
- Include the required one before DLL.bb2
-
- Compare_Strings_S.bb2 This is a case-sensitive routine ("CAT" <> "cat")
- Compare_Strings_I.bb2 This is a case-insensitive routine ("CAT" = "cat")
- Compare_Strings_IL.bb2 This is a case-insensitive routine which treats
- strings as being equal if they have different
- numbers of trailing spaces ("CAT " = "cat")
-
- XINCLUDE Compare_Strings_X.bb2
-
-
-
- Now you need to include the dll routines somewhere near the top of your
- program. This must be after the appropriate Compare_Strings routine.
- It does not matter whether or not the DLL routines are actually executed.
-
- XINCLUDE "DLL.bb2"
-
-
- Next you need to create a newtype for YOUR list item. You must include
- a DLL node as your first variable in the newtype, otherwise you are free
- to do anything a newtype will allow.
-
-
- Newtype .myitem
- node.dll ; Must be the first item
- namestring.s
- amount.w
- cost.l
- End Newtype
-
-
-
- Then you MUST do 3 steps before you can actually use the list.
-
- 1. Create a variable to hold a pointer to the current list item. You do
- this with Deftype and it MUST create a POINTER variable type.
-
- Deftype .myitem *MyItemPtr
-
-
- 2. Initialize the list. This creates the List Header and also creates a
- dummy item.
-
- *MyList.dllhead = INIT_LIST{&*MyItemPtr,SizeOf .myitem}
-
- INIT_LIST is a function of the DLL includes. You must always pass the
- address of your current item pointer to this routine (&*MyItemPtr). To all
- other routines you must pass the head of the list as a pointer.
-
- You must also pass the size of your item, with Sizeof .myitem, as the
- second parameter to the INIT_LIST function. This function returns the
- address of the head of the list (a dllhead type), which you save in a
- pointer, so you can reference the list later on. If you are planning to
- have variable length items, you MUST set this length to at least sufficient
- to include all string variables in the longest item. If there are no
- string items then a minimum of one numeric field must be included after
- the node.
-